package com.dean.action;

import com.dean.entity.DeanResponse;
import com.dean.exception.DeanRuntimeException;
import com.dean.service.PdfMergeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @ClassName EntityGenAction
 * @Description entity生成控制
 * @Author Administrator
 * @Date 2021/10/2315:31
 */
public class PdfMergeAction {
    private final Logger logger = LoggerFactory.getLogger(PdfMergeAction.class);

    private static class CodeGenActionHolder{
        private final static PdfMergeAction INSTANCE = new PdfMergeAction();
    }

    public static PdfMergeAction getInstance(){
        return PdfMergeAction.CodeGenActionHolder.INSTANCE;
    }

    public DeanResponse<String> merge(String source,String target){
        try {
            PdfMergeService mergeService = PdfMergeService.getInstance();
            mergeService.pdfMerge(source,target);
        }catch (Exception e){
            if(e instanceof DeanRuntimeException){
                DeanRuntimeException exception = (DeanRuntimeException) e;
                return DeanResponse.error(exception.getCode(),exception.getMsg());
            }else{
                logger.error(e.getMessage(),e);
                return DeanResponse.error();
            }
        }
        return DeanResponse.ok("操作成功");
    }
}
